package com.fengmi.controller;

import com.fengmi.dto.PageDTO;
import com.fengmi.entity.MallGoodsSpec;
import com.fengmi.entity.ViewSpecOption;
import com.fengmi.service.impl.ViewSpecOptionService;
import com.fengmi.vo.PageResultVO;
import com.fengmi.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 作者：陈学虎
 * 时间：2021/7/8 0008 下午 3:12
 */
@RestController
@CrossOrigin
@Api(description = "规格选项信息")
@RequestMapping("/specOption")
public class ViewSpecOptionController {

    @Autowired
    private ViewSpecOptionService viewSpecOptionService;

    @PostMapping("/findPage")
    @ApiOperation("分页查询规格选项信息")
    public PageResultVO<ViewSpecOption> findPage(@RequestBody PageDTO<ViewSpecOption> pageDTO) {
        return viewSpecOptionService.findPage(pageDTO);
    }

    @PostMapping("/save")
    @ApiOperation("保存规格选项信息")
    public ResultVO save(@RequestBody MallGoodsSpec mallGoodsSpec){
        return viewSpecOptionService.save(mallGoodsSpec);
    }

    @GetMapping("/findAllSpec")
    @ApiOperation("查询所有规格信息")
    public ResultVO findAllSpec(){
        return viewSpecOptionService.findAllSpec();
    }

    @GetMapping("/findOne/{optId}")
    @ApiOperation("根据规选项id查询规格信息")
    public ViewSpecOption findOne(@PathVariable("optId") Integer optId){
        return viewSpecOptionService.findOne(optId);
    }

    @PostMapping("/updateOption")
    @ApiOperation("修改规格选项信息")
    public ResultVO updateOption(@RequestBody ViewSpecOption viewSpecOption){
        return viewSpecOptionService.updateOption(viewSpecOption);
    }

    @DeleteMapping("/delByOptId/{optId}")
    @ApiOperation("删除指定的opt选项")
    public ResultVO delById(@PathVariable("optId") @ApiParam("要删除品牌的id") Integer optId){
        return viewSpecOptionService.delByOptId(optId);
    }
}
